package com.taomus.mytools.simplec.common;

/**
 * @author mrc
 */
public class Token {
	
	private WordEnum code;
	private String symbol;
	private String alias;
	private WordEnum attribute;
	private WordEnum to;
	private boolean isDef=false;
	private int line;
	//作用域层级
	private int level = 0; 

	public Token(final WordEnum code){
		this.code = code;
		this.symbol = code.getSymbol();
	}
	
	public Token(final WordEnum code, final String symbol) {
		this.code = code;
		this.symbol = symbol;
	}

	public WordEnum getCode() {
		return code;
	}

	public void setCode(WordEnum code) {
		this.code = code;
	}

	public String getSymbol() {
		return symbol;
	}

	public void setSymbol(String symbol) {
		this.symbol = symbol;
	}

	@Override
	public String toString() {
		StringBuilder to = new StringBuilder("Token [code:");
		to.append(code);
		to.append(", symbol : ");
		to.append(symbol);
		to.append(" [line ");
		to.append(line);
		to.append("] ");
		if(this.code == WordEnum.ID || this.code == WordEnum.LOCAL){
			to.append(" , (level : ");
			to.append(level);
			to.append(")");
		}
		if(alias != null){
			to.append(", alias : ");
			to.append(alias);
		}
		if(attribute != null){
			to.append(", attribute : ");
			to.append(attribute);
		}
		if(this.to != null && attribute != this.to){
			to.append(", type to :");
			to.append(this.to);
		}
		to.append("]");
		return to.toString();
	}
	
	public WordEnum getAttribute() {
		return attribute;
	}
	
	public void setAttribute(WordEnum attribute) {
		this.attribute = attribute;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public boolean isDef() {
		return isDef;
	}

	public void setDef(boolean isDef) {
		this.isDef = isDef;
	}

	public String getAlias() {
		return alias;
	}

	public void setAlias(String alias) {
		this.alias = alias;
	}

	public int getLine() {
		return line;
	}

	public void setLine(int line) {
		this.line = line;
	}

	public WordEnum getTo() {
		return to;
	}

	public void setTo(WordEnum to) {
		this.to = to;
	}
}
